#!/usr/bin/env python
# -*- encoding: utf-8 -*-

from datetime import datetime
from email.policy import default
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, DateTime, Enum, Text
from sqlalchemy.orm import relationship
from sqlalchemy.dialects.mysql import INTEGER
from models.classroom import Classroom
from models.user import User
from db.database import Base
from common.utils import formatter

class Device(Base):
    __tablename__ = 'device'

    device_id = Column(INTEGER(11), primary_key=True)
    classroom_id = Column(ForeignKey('classroom.classroom_id', ondelete='CASCADE'), nullable=False, index=True)
    device_type = Column(String(255), nullable=False)
    stream_url = Column(String(255), nullable=False)
    key = Column(String(255), nullable=False)
    status = Column(String(255), nullable=False)

    classroom = relationship('Classroom')

    def __init__(self, classroom_id, device_type, stream_url,
                 key,status):
        self.classroom_id = classroom_id
        self.device_type = device_type
        self.stream_url = stream_url
        self.key = key
        self.status = status

    def __repr__(self):
        return 'Device:%s' % self.reservation_id

    def to_dict(self):
        new_dict = {}
        for c in self.__table__.columns:
            new_dict[formatter(c.name)] = getattr(self, c.name, None)
        return new_dict
